package com.qf.lanzhou.shop.api.controller;

import com.qf.lanzhou.shop.pojo.entity.Goods;
import com.qf.lanzhou.shop.pojo.entity.GoodsUrl;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import com.qf.lanzhou.shop.api.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author LEON-HE
 */
@Controller
@Api(tags = "商品接口")
@RequestMapping("/detail")
public class GoodsDetailController extends BaseController {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping(value = "/goods/{goodsId}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据id获取商品")
    public BaseRespVO toGoodsDetail(@PathVariable Long goodsId) {
        Goods goods = goodsService.getGoodsById(goodsId);
        return convertSuccessResult(goods);
    }

    @RequestMapping(value = "/url/{goodsId}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据id获取商品展示图片")
    public BaseRespVO showGoodsUrl(@PathVariable Long goodsId) {
        List<GoodsUrl> goodsUrlById = goodsService.getGoodsUrlById(goodsId);
        return convertSuccessResult(goodsUrlById);
    }
}
